#include "ShapeBase.h"

ShapeBase::ShapeBase()
{
    //ctor
}
char ShapeBase::GetRandom()
{

}

void ShapeBase::MakeSize()
{

    cout<<"Plsase input the level between 1 and 3"<<endl<<endl;
    cout<<"***********************************"<<endl<<endl;
    cout<<"Level 1 --> width=2 length=3"<<endl;
    cout<<"Level 2 --> width=4 length=5"<<endl;
    cout<<"Level 3 --> width=7 length=9"<<endl;
    cout<<"Level:";

    cin>>m_level;

    switch (m_level)
    {
        case 1: m_map_width = 2;
                m_map_length = 3;
                break;
        case 2: m_map_width = 4;
                m_map_length = 5;
                break;
        case 3: m_map_width = 7;
                m_map_length = 9;
                break;
        default:
                  cout<<"select error"<<endl;
    }

    m_map.resize (m_map_length);
    int i;
    for (i=0;i<m_map_length;i++)
    {
        m_map[i].resize (m_map_width);
    }
}

void ShapeBase::BuildMap()
{
    cout<<"The game is building in progress, please wait"<<endl;
    int i,j;
    for (i=0;i<m_map_length;i++)
    {
        for (j=0;j<m_map_width;j++)
        {
            m_map[i][j]=GetRandom();
            sleep(1);
        }
    }
    cout<<"The map has been built"<<endl;
}

void ShapeBase::ShowMap()
{
    system("clear");
    cout<<"Now , the game is beginning,"<<endl;
    cout<<"the map of shape will be on the screen for 5 seconds"<<endl;
    int i,j;
    for (i=0;i<m_map_length;i++)
    {
        for (j=0;j<m_map_width;j++)
        {
            cout<<m_map[i][j]<<' ';
        }
        cout<<endl;
    }
    sleep (5);
    system("clear");
}

void ShapeBase::InputAnswer()
{
    cout<<"Now, please input your answer "<<endl;
    m_score = 0;
    int i,j;
    char tmp;
    for (i=0;i<m_map_length;i++)
    {
        for (j=0;j<m_map_width;j++)
        {
            cin>>tmp;
            if (tmp == m_map[i][j])
              m_score++;
        }
    }
}

void ShapeBase::PlayGame()
{
    MakeSize();
    BuildMap();
    ShowMap();
    InputAnswer();
}

int  ShapeBase::GetScore()
{
    return m_score;
}

int ShapeBase::GetLevel()
{
    return m_level;
}

ShapeBase::~ShapeBase()
{
    //dtor
}


